﻿@model G28BS.Models.UserProfile

<div id="userInfo" >
    
    <div class="profileImg">
        
        @{ string filePath = Request.MapPath("~/Images/Profile/"+ @Model.userImage);}
        @if( System.IO.File.Exists(filePath))
        {
            <img class="userImage" src="~/Images/Profile/@Model.userImage" alt="unable to load image" />
        }
        else
        {
            <img class="userImage" src="~/Images/avatar.png" alt="unable to load image"/>   
        }

        
        <h4>@Model.UserName</h4>
    </div>

    <div class="userReviews">

        <p>User Reviews</p>
        @{var numStars = 5;}
        @{ 
            int PosRev;
            if( Model.gameCount > 0 )
            {
                PosRev = Convert.ToInt16(Math.Round((Model.gameCount - Model.negativeReviewCount) * numStars / ((float)Model.gameCount))); 
            }
            else
            {
                PosRev = numStars;   
            }
          }
        <div>
            @for (var i = 0; i < PosRev; i++)
            { 
                <img src="~/Images/star_gold.png" alt="" />
            }
            @for (var i = 0; i < (numStars - PosRev); i++)
            {
                <img src="~/Images/star_grey.png" alt="" />
            }
        </div>

        <p >Play Reliability</p>
        @{
            int reliability;
            if (Model.gameCount > 0)
            {
                reliability = Convert.ToInt16(Math.Round((Model.gameCount - Model.gameDefaultCount) * numStars / ((float)Model.gameCount)));
            }
            else
            {
                reliability = numStars;
            }   
         }
        <div>
            @for (var i = 0; i < reliability; i++ )
            {
                <img src="~/Images/star_gold.png" alt="" />
            }
            @for (var i = 0; i < (numStars - reliability); i++ )
            {
                <img src="~/Images/star_grey.png" alt="" />
            }
        </div>
    </div>

    <!-- Getting current session user id and compare with profile user id
        input to decide whether to allow edit profile or not-->
    @using System.Web;
    @using System.Web.Security;
    @{
        int value;
        value=WebSecurity.CurrentUserId;
    }
    <div class="userDescription">
        <p>your description: </p>
        <p>@Model.userDescription</p>
    </div>
    
</div>
<div class="link">
        
    @if (value == Model.UserId)
    {
        @Html.ActionLink("Edit your profile", "EditProfile")
    }
    else
    {
        @Html.ActionLink("your profile", "MyProfile")
    }
        
</div>
